/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-06-09     WangJing       the first version
 */
#ifndef SOFTWARE_RINGBUFFER_H_
#define SOFTWARE_RINGBUFFER_H_

#include "stm32f4xx_hal.h"

typedef struct {
    uint16_t head;
    uint16_t tail;
    uint8_t *buf;
    uint32_t size;
} RingBuffer_t;

void ringBuf_init(RingBuffer_t *rb, uint8_t *buffer, uint32_t size);
uint8_t ringBuf_isEmpty(RingBuffer_t *rb);
uint8_t ringBuf_isFull(RingBuffer_t *rb);
uint8_t ringBuf_write(RingBuffer_t *rb, uint8_t data);
uint8_t ringBuf_read(RingBuffer_t *rb, uint8_t *data);
uint32_t ringBuf_getUsed(RingBuffer_t *rb);
uint32_t ringBuf_getFree(RingBuffer_t *rb);

#endif /* SOFTWARE_RINGBUFFER_H_ */
